/**********************************************************************************
**
** Copyright (C) 2009 Jostein Bratlie
** Contact: jostein.bratlie@gmail.com | http://bratlie.info | http://episteme.hin.no
**
** This file is part of GMQtExt, a GMlib and Qt extension library
**
** GMQtExt is free software: you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** GMQtExt is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with GMQtExt.  If not, see <http://www.gnu.org/licenses/>.
**
**********************************************************************************/

#ifndef PROPERTYBROWSER_H
#define PROPERTYBROWSER_H


// Qt
#include <QString>
#include <QVariant>
#include <QWidget>

// Qt Solutions
class QtProperty;
class QtVariantProperty;
class QtGroupPropertyManager;
class QtVariantPropertyManager;
class QtTreePropertyBrowser;
class QtBrowserItem;



// GMlib
//namespace GMlib {
//
//  class Scene;
//}




namespace GMQtExt {

  enum PROPERTYSTATUS {
    PROPERTY_INVALID,
    PROPERTY_UNCHANGED,
    PROPERTY_CHANGED
  };

  class PropertyBrowser : public QWidget {
  Q_OBJECT
  public:
    PropertyBrowser( QWidget* parent = 0x0 );
    virtual ~PropertyBrowser();


  protected:
    virtual void                    beginSetup();
    virtual void                    endSetup();
    virtual void                    beginUpdate();
    virtual void                    endUpdate();

    QtProperty*                     createGroup(
        const QString& name,
        const QString& identifier,
        QtTreePropertyBrowser* browser,
        bool default_exp = false
        );
    QtProperty*                     createGroup(
        const QString& name,
        const QString& identifier,
        QtProperty* parent_group,
        bool default_exp = false
        );
    QtVariantProperty*              createVariantLabel(
        int property_type,
        const QString& name,
        const QVariant& value,
        const QString& identifier,
        QtProperty* group = 0x0,
        bool default_exp = false
        );
    QtVariantProperty*              createVariantProperty(
        int property_type,
        const QString& name,
        const QVariant& value,
        const QString& identifier,
        QtProperty* group = 0x0,
        bool default_exp = false,
        QtVariantPropertyManager* manager = 0x0
        );

    QtTreePropertyBrowser*          getBrowser() const;
    QtGroupPropertyManager*         getGroupManager() const;
    QtVariantPropertyManager*       getLabelManager() const;
    QtProperty*                     getProperty( const QString& property_id ) const;
    QtVariantProperty*              getVariantProperty( const QString& property_id ) const;
    QVariant                        getVariantPropertyValue( const QString& property_id, PROPERTYSTATUS& property_status ) const;
    QString                         getPropertyId( QtProperty* property ) const;
    PROPERTYSTATUS                  getPropertyStatus( const QString& property_id ) const;
    QtVariantPropertyManager*       getVariantPropertyManager() const;

    void                            markPropertyAsChanged( QtProperty* property );
    void                            registerProperty( QtProperty* property, const QString& identifier, bool default_exp );
    void                            setBackgroundColor( QtProperty* property, const QColor& color );

  protected slots:
    virtual void                    slotVariantPropertyChanged( QtProperty*, const QVariant& );

  private slots:
    void                            _slotBrowserItemCollapsed( QtBrowserItem *item );
    void                            _slotBrowserItemExpanded( QtBrowserItem *item );

  private:
    QtTreePropertyBrowser           *_browser;

    QMap<QString, bool>             _property_id_status;
    QMap<QtProperty*, QString>      _property_id;
    QMap<QString, bool>             _property_exp;

    QtGroupPropertyManager          *_group_manager;
    QtVariantPropertyManager        *_label_manager;
    QtVariantPropertyManager        *_vp_manager;

  signals:
    void                            signPropertyChanged();

  }; // END class PropertyBrowser

} // END namespace GMQtExt







#endif // PROPERTYBROWSER_H
